import request from '@/utils/request'

// 获取提案部门列表
export function getProList() {
  return request({
    url: '/admins/getProList',
    method: 'get'
  })
}

// 获取社情民意部门列表
export function getPubList() {
  return request({
    url: '/admins/getPubList',
    method: 'get'
  })
}

// 添加提案部门
export function addProDepartment(data) {
  return request({
    url: '/admins/addProDepartment',
    method: 'post',
    data
  })
}

// 添加社情民意部门
export function addPubDepartment(data) {
  return request({
    url: '/admins/addPubDepartment',
    method: 'post',
    data
  })
}

// 删除提案部门
export function deleteProDepartment(id) {
  return request({
    url: `/admins/deleteProDepartment/${id}`,
    method: 'delete'
  })
}

// 删除社情民意部门
export function deletePubDepartment(id) {
  return request({
    url: `/admins/deletePubDepartment/${id}`,
    method: 'delete'
  })
}

// 修改管理员密码
export function updatePassword(aid, newPassword) {
  return request({
    url: `/admins/updatePassword/${aid}`,
    method: 'put',
    params: {
      newPassword
    }
  })
}

// 获取管理员列表
export function getAdmins(pageNum, pageSize, sortType, permissionType, statusType, searchText) {
  return request({
    url: '/admins/getAdmins',
    method: 'get',
    params: {
      pageNum,
      pageSize,
      sortType,
      permissionType,
      statusType,
      searchText
    }
  })
}

// 注销管理员
export function disableAdmin(aid) {
  return request({
    url: `/admins/disable/${aid}`,
    method: 'put'
  })
}

// 根据管理员 ID 查询管理员信息
export function getAdminById(aid) {
  return request({
    url: `/admins/getAdminById/${aid}`,
    method: 'get'
  })
}

// 更新管理员信息
export function updateAdmin(data) {
  return request({
    url: `/admins/updateAdmin/${data.aid}`,
    method: 'put',
    data
  })
}

// 新增普通管理员
export function addAdmin(data) {
  return request({
    url: '/admins/addAdmin',
    method: 'post',
    data
  })
}

// 导出管理员数据
export function exportAdmins(sortType, permissionType, statusType, searchText) {
  const params = new URLSearchParams({
    sortType: sortType || 'asc',
    permissionType: permissionType || 'all',
    statusType: statusType || 'all',
    searchText: searchText || ''
  }).toString();

  return request({
    url: `/admins/exportAdmins?${params}`,
    method: 'get',
    responseType: 'blob',
    timeout: 60000,
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    }
  });
}

// 检查账号是否存在
export function checkAccountExists(account)  {
  return request.get(`/admins/checkAccount/${account}`);
}




